﻿@{
    ViewBag.Title = "UserList";
    Layout = "~/_Layout.cshtml";
}
<div style="height: auto;">
    <table id="div_ourinfo" class="tab"></table>
</div>
<script type="text/javascript">
    $(function () {
        var url = '@Url.Action("GetOurInfo", "User")'
        SendAjax("get", url, { ran: Math.random() }, "json", function (data) {
            data = data.Data;
            if (data == null || data.length == 0) {
                return;
            }
            RenderData(data);
        });
    })

    function RenderData(data) {
        var html = "";
        html += "<tr>";
        html += "<td>姓名</td>";
        html += "<td>生日</td>";
        html += "<td>电话</td>";
        html += "<td style='width:190px;'>爱好</td>";
        html += "<td>操作</td>";
        html += "</tr>";
        for (var i = 0; i < data.length; i++) {
            html += "<tr>";
            html += "<td>" + data[i].Name + "</td>";
            html += "<td>" + data[i].Birthday + "</td>";
            html += "<td>" + data[i].Phone + "</td>";
            html += "<td title='" + data[i].Hobbies + "'>" + cutStr(data[i].Hobbies, 10) + "</td>";
            if (data[i].Uid == '@ViewData["uid"].ToString()') {
                html += "<td><a tag='edit' uid='" + data[i].Uid + "' href='javascript:void(0);'>编辑</a></td>";
            }
            else {
                html += "<td><a tag='info' uid='" + data[i].Uid + "' href='javascript:void(0);'>查看</a></td>";
            }
            
            html += "</tr>";
        }
        $("#div_ourinfo").append($(html));

        $("#div_ourinfo a[tag=info]").each(function () {
            this.addEventListener("click", function () { GetUserInfo(this,"info"); }, false);
        })

        $("#div_ourinfo a[tag=edit]").each(function () {
            this.addEventListener("click", function () { GetUserInfo(this,"edit"); }, false);
        })
    }

    function GetUserInfo(obj,tag)
    {
        var id = $(obj).attr("uid");
        var url = '@Url.Action("UserInfo","User")'
        url = url + "?tag=" + tag + "&uid=" + id;

        window.location.href = url;
    }
</script>
